<?php
class colorboxWidget extends CWidget
{
	public $clientScript;
	
	public $baseUrl;
	public $Jscripts = array('jquery.colorbox.js');
	public $Cssscript = 'colorbox.css';
	
	public $theme = 'example1';
	
	public $id='box';
	
	public $options;	//transition:"none", width:"75%", height:"75%"

   /**
    * Publishes the assets
    */
   public function publishAssets()
   {
      $dir = dirname(__FILE__).DIRECTORY_SEPARATOR;
 
      $this->baseUrl = Yii::app()->getAssetManager()->publish($dir);
   }
   
   /**
    * Registers the external javascript files
    */
   public function registerClientScripts()
   {
      if ($this->baseUrl === '')
         throw new CException('Can not find the base folder');

      $this->clientScript = Yii::app()->getClientScript();

//      $this->clientScript->registerCoreScript('jquery');
      foreach ($this->Jscripts as $script)
      {
       $this->clientScript->registerScriptFile($this->baseUrl.'/colorbox/'.$script,CClientScript::POS_END);     	
      }


      
      $this->clientScript->registerCssFile($this->baseUrl.'/'.$this->theme.'/'.$this->Cssscript);
   }
   
   public function registerScript()
   {
   		$script = <<<SCRIPT
   			
   		$('$this->id').colorbox({{$this->options}});
   		
SCRIPT;
		Yii::app()->getClientScript()->registerScript('ext-box-colorbox-'.$this->id,$script,CClientScript::POS_READY);
   }
   
	public function run()
	{
		$this->publishAssets();
		$this->registerClientScripts();
		$this->registerScript();
		
//		$this->render($this->view);	
	}

}
?>